package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteBrandService;
import com.spzx.product.api.domain.Brand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RemoteBrandServiceFactory implements FallbackFactory<RemoteBrandService> {
    @Override
    public RemoteBrandService create(Throwable cause) {

        log.error("品牌服务调用失败:{}", cause.getMessage());

        return new RemoteBrandService() {
            @Override
            public R<List<Brand>> listAllBrands() {
                return R.fail("获取所有品牌数据失败:" + cause.getMessage());
            }
        };
    }
}
